<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Login extends Controller{
    public function login(){
        return $this->fetch();
    }
    public function doLogin(){
    	$username = input("param.username");
        $password = input("param.password");
        $verifycode = input("param.verifycode");
        $hasUser = Db::name('admin')->where(['username'=> $username,'status'=>1])->find();
        if(empty($hasUser)){
        	return json(['code' => 501, 'url' => '', 'msg' => '用户不存在']);
        }elseif(md5('tmd'.$password)!=$hasUser['password']){
        	return json(['code' => 502, 'url' => '', 'msg' => '密码错误']);
        }elseif(!captcha_check($verifycode)){
        	return json(['code' => 503, 'url' => '', 'msg' => '验证码错误']);
		}else{
        	session('username', $username);
			// cookie('password', $password, 3600);
        	return json(['code' => 200, 'url' => url('index/index'), 'msg' => '成功登录']);
        }
    }
    public function loginOut(){
    	session('username',null);
    	// cookie('password',null);
        $this->redirect(url('login/login'));
    }
}
